/*
 * @Author: zhangyun
 * @Date: 2021-04-26 09:38:04
 * @LastEditors: zhangyun
 * @LastEditTime: 2021-04-26 16:01:58
 * @Desc:
 */
const mongoose = require('../db/dbServer')
// shema
const userSchema = new mongoose.Schema({
  user: { type: String, require: true, unique: true }, //字段是否唯一
  pwd: {
    type: String,
    set(val) {
      // 通过bcryptjs对密码加密返回值 第一个值返回值， 第二个密码强度
      return require('bcryptjs').hashSync(val, 10)
    },
    require: true,
  },
  sex: { type: String, require: false },
})
// model
const userModel = mongoose.model('user', userSchema)

module.exports = userModel
